package com.hut.oa.service;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hut.oa.model.bean.NoteDir;
import com.hut.oa.model.bean.Notes;
import com.hut.oa.model.bean.User;
import com.hut.oa.model.dao.note.NoteDao;
import com.hut.oa.model.dao.note.NoteDirDao;
import com.hut.oa.model.mapper.NotesMapper;

@Service
@Transactional
public class NoteService {

	@Autowired
	NoteDao ndao;
	
	@Autowired
	NoteDirDao dirnotedao;
	
	@Autowired
	NotesMapper notemapper;
	
	public void deletenotedir(NoteDir dirid,User u){
		List<Notes> list=ndao.findByUserIdAndIsDeleteAndDir(u, 0, dirid);
		for (Notes notes : list) {
			if(notemapper.selectnotebynoteid(notes.getId()).size()>0){
		 		notemapper.deletebynoteid(notes.getId());
		 	}
			ndao.delete(notes.getId());	
		}
		dirnotedao.delete(dirid);
	}
}
